datetime does not work with non-constant pytz.timezone
authorDebian Science Maintainers <debian-science-maintainers@lists.alioth.debian.org>
Tue, 9 Dec 2025 11:19:37 +0000 (11:19 +0000)
committerGraham Inggs <ginggs@debian.org>
Tue, 9 Dec 2025 11:19:37 +0000 (11:19 +0000)
This has always been the case (and is explicitly warned about
in the pytz documentation), but became a test fail when
tzdata 2024b changed 'CET' and similar to aliases.

Author: Rebecca N. Palmer <rebecca_palmer@zoho.com>
Forwarded: no

Gbp-Pq: Name no_pytz_datetime.patch

pandas/tests/arrays/test_array.py

index 158a963845b066139868de6905f45c83da1ca4bb..c09a75bbb7560113f23b5729a7599eebefddcc55 100644 (file)
@@ -306,7 +306,8 @@ def test_array_copy():
     assert tm.shares_memory(a, b)
 
 
-cet = pytz.timezone("CET")
+cetfixed = pytz.timezone("Etc/GMT-1") # the wrong-looking sign is because Etc/* use posix convention, as described in the tzdata source
+cetwithdst = pytz.timezone("Europe/Brussels")
 
 
 @pytest.mark.parametrize(
@@ -347,11 +348,20 @@ cet = pytz.timezone("CET")
         ),
         (
             [
-                datetime.datetime(2000, 1, 1, tzinfo=cet),
-                datetime.datetime(2001, 1, 1, tzinfo=cet),
+                datetime.datetime(2000, 1, 1, tzinfo=cetfixed),
+                datetime.datetime(2001, 1, 1, tzinfo=cetfixed),
             ],
             DatetimeArray._from_sequence(
-                ["2000", "2001"], dtype=pd.DatetimeTZDtype(tz=cet, unit="ns")
+                ["2000", "2001"], dtype=pd.DatetimeTZDtype(tz=cetfixed, unit="ns")
+            ),
+        ),
+        (
+            [
+                cetwithdst.localize(datetime.datetime(2000, 1, 1)),
+                cetwithdst.localize(datetime.datetime(2001, 1, 1)),
+            ],
+            DatetimeArray._from_sequence(
+                ["2000", "2001"], dtype=pd.DatetimeTZDtype(tz=cetwithdst, unit="ns")
             ),
         ),
         # timedelta